package com.servlet;

import com.entity.Students;
import com.tools.Utils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class LikeStu {
    //模糊查询，详见SelectAll
    List<Students> getlist(String sname){
        List<Students> list=new ArrayList<>();
        String sql="SELECT * FROM students WHERE sname LIKE '%"+sname+"%'";
        Connection conn= Utils.getConn();
        try {
            Statement stat = conn.createStatement();
            ResultSet res=stat.executeQuery(sql);
            while (res.next()){
                Students stu=new Students();
                stu.setSid(res.getInt("sid"));
                stu.setSname(res.getString("sname"));
                stu.setSage(res.getString("sage"));
                stu.setSclass(res.getString("sclass"));
                list.add(stu);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
